const SMSClient = require('@alicloud/sms-sdk');
const accessKeyId = 'LTAImZ3YpYs5vzsG';
const secretAccessKey = 'MqSMWJjCyJewD5fsYJIJvWHD5TLc45';
class Db_fun{ 
	// 通知短信
	notice_user(phone,name,deviceid,warntype,warngrade,cb){	    
	    //初始化sms_client
	    let smsClient = new SMSClient({accessKeyId, secretAccessKey});
	    var send_data = {
	        name:name,
	        deviceid:deviceid,
	        warntype:warntype,
	        warngrade:warngrade
	    }
	    //发送短信
	    smsClient.sendSMS({
	        PhoneNumbers: phone,
	        SignName: '阿里云短信测试专用',
	        TemplateCode: 'SMS_119081356',
	        TemplateParam: JSON.stringify(send_data)
	    }).then(function (data) {
	        let {Code} = data
	        if (Code === 'OK') {
	            //处理返回参数
	            // console.log(Code);
	            if (cb != null) {
	                cb(1,'ok');
	            }
	        }
	    }, function (err) {
	        console.log(err)
	    })
	}
	// 验证码注册短信:
	register_user(phone,code,cb){
        //初始化sms_client
	    let smsClient = new SMSClient({accessKeyId, secretAccessKey});
	    var send_data = {
	        code:code
	    }
	    //发送短信
	    smsClient.sendSMS({
	        PhoneNumbers: phone,
	        SignName: '中达bim',
	        TemplateCode: 'SMS_109735206',
	        TemplateParam: JSON.stringify(send_data)
	    }).then(function (data) {
	        let {Code} = data
	        if (Code === 'OK') {
	            //处理返回参数
	            // console.log(Code);
	            if (cb != null) {
	                cb(1,'ok');
	            }
	        }
	    }, function (err) {
	        console.log(err)
	    })
	}
	// 修改密码：SMS_109735205
	modify_pass(phone,code,cb){
        //初始化sms_client
	    let smsClient = new SMSClient({accessKeyId, secretAccessKey});
	    var send_data = {
	        code:code
	    }
	    //发送短信
	    smsClient.sendSMS({
	        PhoneNumbers: phone,
	        SignName: '中达bim',
	        TemplateCode: 'SMS_109735205',
	        TemplateParam: JSON.stringify(send_data)
	    }).then(function (data) {
	        let {Code} = data
	        if (Code === 'OK') {
	            //处理返回参数
	            // console.log(Code);
	            if (cb != null) {
	                cb(1,'ok');
	            }
	        }
	    }, function (err) {
	        console.log(err)
	    })
	}
}
module.exports = new Db_fun();